<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>192.168.1.126:5500</h1>
    <script>
        var Animal = function (name, gender, age, color) {
            this.type = "动物"
            this.name = name
            this.gender = gender
            this.age = age
            this.color = color
        }
        Animal.prototype.eat = function (food = "食物") {
            console.log(this.name + "吃" + food)
        }
        Animal.prototype.sleep = function () {
            console.log(this.name + "睡觉了")
        }
        Animal.prototype.introduceSelf = function () {
            console.log(`
                我叫${this.name},今年${this.age}岁,
                我是个${this.gender}生,我是${this.color}色的${this.type}
                `)
        }
        Animal.prototype.sayHello = function () {
            console.log("Hello")
        }

        var Cat = function () {
            //借用函数
            Animal.apply(this, arguments)
            this.type = "猫"
        }
        //原型对象  概念：继承
        //子类.原型对象 指向 父类的实例
        Cat.prototype = new Animal()

        var cat1 = new Cat("Simba", "男", 3, "红")
        cat1.introduceSelf()

        var Dog = function () {
            //借用函数  克隆父类实例属性和方法
            Animal.apply(this, arguments)
            this.type = "狗"
        }
        //克隆父类的原型属性和方法
        Dog.prototype = new Animal()
        var dog1 = new Dog("Roger", "女", 1, "黑")
        dog1.introduceSelf()
        dog1.sayHello()
    </script>
</body>

</html>
